import { isSSR } from '@/utils/is'

export const set = (key: string, value: any) => {
  if (isSSR) {
    return
  }
  localStorage.setItem(key, value)
}

export const get = (key: string) => {
  if (isSSR) {
    return
  }
  const data = localStorage.getItem(key)
  return data
}

export const setJson = (key: string, value: any) => {
  if (isSSR) {
    return
  }
  localStorage.setItem(key, JSON.stringify(value))
}

export const getJson = (key: string) => {
  if (isSSR) {
    return
  }
  const data = localStorage.getItem(key)
  if (data) {
    return JSON.parse(data)
  }
  return data
}

export const remove = (key: string) => {
  if (isSSR) {
    return
  }
  localStorage.removeItem(key)
}

export const clear = () => {
  if (isSSR) {
    return
  }
  localStorage.clear()
}
